"""
关注加油站
"""
import os
import sys
import django
import urllib.parse
import base64

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(BASE_DIR)
sys.path.insert(0, BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'finance_c2c.settings'
django.setup()

from core.yl.client import yl_oauth

import base64
from gmssl import sm2


def ms2_test():
    # 16进制的公钥和私钥
    # private_key = '3133418244880416717548500844444709504898209856981063800207458518484025066376'
    # public_key = '044774DA78D321CE42AAE6001A31F1BF0522B5BF578D3C31790D0DFBA222E2DE40B5BACB8E2530F29E55D77D629DA96F4135B1637E934E541371767727CB1CBFBE'

    private_key = '00B9AB0B828FF68872F21A837FC303668428DEA11DCD1B24429D0C99E24EED83D5'
    public_key = 'B9C9A6E04E9C91F7BA880429273747D7EF5DDEB0BB2FF6317EB00BEF331A83081A6994B8993F3F5D6EADDDB81872266C87C018FB4162F5AF347B483E24620207'


    sm2_crypt = sm2.CryptSM2(private_key, public_key)

    data = b"111"
    enc_data = sm2_crypt.encrypt(data)
    dec_data = sm2_crypt.decrypt(enc_data)
    print(dec_data == data)


if __name__ == '__main__':
    ms2_test()
    # data = {
    #     "platId": "643924998417027072",
    #     "openId": "ojZNEwQtvA6HfpQW32xijnPYaU-M",
    #     "channelId": "200714002",
    #     "phone": "7B32BA6C860C607E8CF1358196F323BB",
    # }
    # response = yl_oauth.get_token(data)
    # print(response, "token response")
    # if response.get("code") == "200":
    #     token = response.get("token")
    #     aes_decrypt_token = yl_oauth.aes_decrypt_content(token)
    #     print(aes_decrypt_token)
    #     print(type(aes_decrypt_token))
    #     sm2_encrypt_token = yl_oauth.sm2_encrypt(base64.b16encode(aes_decrypt_token))
    #     data["token"] = sm2_encrypt_token
    #     print(data)
    #     response = yl_oauth.check_token(data)
    #     print(urllib.parse.unquote(response))
